<template>
    <div>
        <div class="header-info">
            <p>{{ action_name }}-新闻资讯</p>
            <div>
                <el-button size="mini" @click="$router.push('/cms/article/add')" v-if="action=='edit'">新建</el-button>
                <el-button size="mini" @click="save_click" type="primary"> 保存</el-button>
            </div>
        </div>
        <el-row :gutter="12" type="flex">
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>基本信息</span>
                    </div>
                    <kv label="分站">
                        <selector type="radio" v-model="info.city" url="/zu/sub-site/list?skip=0&take=50"
                                  @loaded="(res)=>{res.data.data = res.data.data.map(it=>it.city);}"
                                  fields="code,name"/>
                    </kv>
                    <kv label="标题">
                        <el-input v-model="info.name"/>
                    </kv>
                    <kv label="内容摘要">
                        <el-input v-model="info.bodySummary"/>
                    </kv>
                    <kv>
                        <label slot="k">封面图</label>
                        <upload
                                :maxCount="1"
                                v-model="info.logo"
                                fileType="img"
                                scales="16:9"
                                :maxWidth="1024"
                                maxSize="5M"
                        ></upload>
                    </kv>
                    <kv label="文章分类">
                        <ref-article-group :multi="true" v-model="info.groups"></ref-article-group>
                    </kv>
                    <!--          <kv label="城市">-->
                    <!--            <my-city v-model="info.city"/>-->
                    <!--          </kv>-->
                    <!--          <kv label="特殊标记">-->
                    <!--            <el-input v-model="info.code"/>-->
                    <!--          </kv>-->
                    <kv label="作者">
                        <el-input v-model="info.author"/>
                    </kv>
                    <kv label="推荐">
                        <selector type="radio" v-model="info.recommend" :data="{true:'是',false:'否' }"/>
                    </kv>
                    <kv label="来源">
                        <el-input v-model="info.source"/>
                    </kv>
                    <kv label="点击量">
                        <el-input v-model="info.clickCount"/>
                    </kv>
                    <!--          <kv label="标签">-->
                    <!--            <el-input v-model="info.tags"/>-->
                    <!--          </kv>-->
                    <kv label="发布时间">
                        <el-date-picker v-model="info.createAt" placeholder="选择日期时间" type="datetime" disabled/>
                    </kv>
                    <!--          <kv label="更新时间">-->
                    <!--            <el-date-picker v-model="info.updateAt" placeholder="选择日期时间" type="datetime" disabled/>-->
                    <!--          </kv>-->
                </el-card>
            </el-col>
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>扩展信息</span>
                    </div>

                    <!--                    <kv label="所属企业">-->
                    <!--                       <ref-corp v-model="info.corp"></ref-corp>-->
                    <!--                    </kv>-->
                    <!--          <kv label="排序">-->
                    <!--            <el-input v-model="info.order"/>-->
                    <!--          </kv>-->
                    <!--          <kv label="链接的其它文章">-->
                    <!--            <el-input v-model="info.linkArticles"/>-->
                    <!--          </kv>-->
                    <!--          <kv>-->
                    <!--            <label slot="k">链接的商品</label>-->
                    <!--            <upload-->
                    <!--                :maxCount="99"-->
                    <!--                v-model="info.linkProducts"-->
                    <!--                fileType="img"-->
                    <!--                scales="16:9"-->
                    <!--                :maxWidth="1024"-->
                    <!--                maxSize="5M"-->
                    <!--            ></upload>-->
                    <!--          </kv>-->
                    <!--          <kv label="评论">-->
                    <!--            <el-input v-model="info.discussions"/>-->
                    <!--          </kv>-->

                    <!--                    <el-input v-model="info.body"/>-->
                    <txt v-model="info.body"/>

                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<style scoped>
</style>
<script>
    /**
     * Created by CodeGenerator
     */
    import refcorp from "../home/EmptyRef"
    import txt from "../common/Text"
    import RefArticleGroup from "./ArticleGroupRef";

    export default {
        components: {
            RefArticleGroup,
            "ref-corp": refcorp,
            txt
        },
        props: {
            value: {type: String, default: ""}
        },
        data() {
            return {

                //URL参数
                action: "",
                action_name: "",
                id: "",
                info: {
                    name: '',
                    city: {
                        name: ''
                    }
                }, //子对象需要声明。
                title: '',
                txtValue: ""
            }
        },
        watch: {
            action(val) {
                this.action_name = {add: "添加", edit: "修改"}[val]
            }
        },
        mounted() {
            this.action = this.$route.params.action;
            this.id = this.$route.query.id;

            this.loadData()
        },
        methods: {
            loadData() {
                if (!this.id) return;
                this.$http.post("/cms/article/detail?id=" + this.id).then(res => {
                    this.info = res.data.data;
                });
            },
            save_click() {
                //校验
                if (jv.main.chk() == false) {
                    return;
                }

                this.$http.post("/cms/article/save", this.info).then(res => {
                    jv.info(this.action_name + " 成功");
                    if (this.action === "add") {
                        this.$router.push("/cms/article/edit?id=" + res.data.data)
                    }
                    if (this.action === "edit") {
                        this.$router.push("/cms/article/list")
                    }
                })
            },

        }
    }
</script>
